package com.ruicar.afs.cloud.afscase.contract.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ruicar.afs.cloud.afscase.contract.service.AggregationService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.modules.contract.cms.vo.CmsProgressInquiryDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/aggregation")
@AllArgsConstructor
@Api(description = "合同聚合接口")
public class AggregationController {
    private final AggregationService aggregationService;

    @RequestMapping(value = "/getLoanProgress", method = RequestMethod.POST)
    @ApiOperation(value = "获取贷前贷款进度")
    public IResponse<CmsProgressInquiryDataVo> getLoanProgress(@RequestParam(value = "idCard",required = false) String idCard,@RequestParam(value = "applicationNo",required = false) String applicationNo){
        if((StringUtils.isBlank(idCard)||"null".equals(idCard))&&(StringUtils.isBlank(applicationNo)||"null".equals(applicationNo))){
            return IResponse.fail("证件号和申请编号不能同时为空");
        }
        if(StringUtils.isNotBlank(idCard)&&!"null".equals(idCard)){
            return IResponse.success(aggregationService.getLoanProgressByIdCard(idCard));
        }else{
            return IResponse.success(aggregationService.getLoanProgressByApplyNo(applicationNo));
        }
    }
}
